/**
 * futures : masterlink.futures.dao.FunctionDao.java
 */
package masterlink.futures.dao;

import java.util.List;

import masterlink.futures.vo.Employee;
import masterlink.futures.vo.Function;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 * TODO Write the description
 *
 * @author : tonyyang
 * Create date : 2011/10/25
 * @version 1.0.0	
 */
@Repository
@Qualifier("FunctionDao")
public class FunctionDao extends TimesTenHibernateDao<Function, Long> {
	
	private static final String FIND_ALL="from Function order by seq";
	private static final String FIND_BY_EMP="select a.* from sys_function a where a.fun_common='Y' "+
											"or a.fun_id in (select fun_id from sys_emp_fun where empno=? ) "+
											"order by a.fun_seq";
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Function> findAll() {
		return (List<Function>) findByHql(FIND_ALL);
	}
	
	public List<Function> findByEmp(Employee emp) {
		if(emp!=null){
			return (List<Function>) findBySql(FIND_BY_EMP, Function.class, emp.getEmpno());
		}
		return null;
	}
	
}
